package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.PageResult;
import com.woniu.pojo.Gym;
import com.woniu.mapper.GymMapper;
import com.woniu.service.IGymService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.vo.GymQueryImgVo;
import com.woniu.vo.GymQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dong
 * @since 2022-10-12
 */
@Service
public class GymServiceImpl extends ServiceImpl<GymMapper, Gym> implements IGymService {

    @Autowired(required = false)
    private GymMapper gymMapper;

    /**
     * 场馆分页模糊查询
     * @param currentPage
     * @param pageSize
     * @param gymQueryVo
     * @return
     */
    public PageResult search(Integer currentPage, Integer pageSize, GymQueryVo gymQueryVo) {
        // 创建分页对象
        IPage<Gym> iPage = new Page<>(currentPage, pageSize);
        // 构建查询对象
        QueryWrapper<Gym> wrapper = new QueryWrapper<>();
        if(gymQueryVo != null){
            if(!StringUtils.isEmpty(gymQueryVo.getName())){
                wrapper.like("name", gymQueryVo.getName());
            }
        }
        // 调用数据访问层 查询
        IPage<Gym> gymIPage = gymMapper.selectPage(iPage, wrapper);
        return new PageResult(gymIPage.getTotal(), gymIPage.getRecords());
    }

    @Override
    public List<Gym> queryGymAll() {
        return gymMapper.selectGymAll();
    }

    @Override
    public List<Gym> queryByName(String name) {
        return gymMapper.selectByName(name);
    }

    @Override
    public List<GymQueryImgVo> queryByImg(String id) {
        return gymMapper.selectByImg(id);
    }
}
